package com.cf.user.login.filter;

import com.cf.user.login.LocalRequestHolder;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * awm-boot-RequestAwareFilter
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/6/15 上午 11:02
 */
@Slf4j
public class RequestAwareFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) {
        log.info("实例化RequestAwareFilter。。。");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        LocalRequestHolder.set((HttpServletRequest) request, (HttpServletResponse) response);
        chain.doFilter(request, response);
        LocalRequestHolder.clean();
    }

    @Override
    public void destroy() {
        log.info("销毁RequestAwareFilter。。。");
    }
}
